package com.example.testing.flags;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.example.testing.R;
import com.example.testing.launchmode.SingleInstanceActivity;
import com.example.testing.launchmode.SingleTaskActivity;
import com.example.testing.launchmode.SingleTopActivity;
import com.example.testing.launchmode.StandardActivity;

/**
 * 如果该Activity为标准模式，那么用FLAG_ACTIVITY_CLEAR_TOP去启动该Activity，则该Activity会和其之上的Activity一起出栈
 * 系统会创建新的Actiivty实例并放入栈顶，singleTask默认有该属性。
 *
 * 该模式和Intent.FLAG_ACTIVITY_SINGLE_TOP组合使用，可以实现类似singleTask的效果，当实例已经存在，则清除其上当Activity,
 * 并调用onNewIntent方法，并不能开辟新当任务栈
 */
public class ClearTopActivity extends Activity {
    private static final String TAG = "ClearTopActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.e(TAG, "onCreate: ");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_flags_cleartop);
        findViewById(R.id.tv_flags).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(ClearTopActivity.this, FlagsActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onNewIntent(Intent intent) {
        Log.e(TAG, "onNewIntent: ");
        super.onNewIntent(intent);
    }
}
